home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
CRS
/
crs56.d81
/
graph.sfx
/
graph.c
next >
Wrap
Text File
|
1990-02-12
|
9KB
|
343 lines
/* GRAPHIC.C */
/*****************************************************************************/
/* ┬ASIC ╔╧ ROUTINES FOR THE ╓─├ CHIP */
/* */
/* ╘HE FOLLOWING ├128 ROUTINES WERE USED TO SPEED UP OPERATIONS TO THE ╓─├ */
/* */
/* ┬┴╬╦ ┴──╥┼╙╙ ╬┴═┼ */
/* ▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐ */
/* 15 $├──┴ ╥┼┴─╥┼╟ ╥EAD A VALUE FROM ╓─├ REG # IN ╪, VALUE IS */
/* IS RETURNED IN ┴. */
/* */
/* 15 $├─├├ ╫╥╔╘┼╥┼╟ ╫RITE A VALUE TO ╓─├ REG # IN ┴, VALUE IS IN */
/* ╪ REG. */
/* */
/* 15 $├┼0├ ╔╬╔╘80 ╥ESET ╓─├ TO DEFAULT CONDITIONS AND LOAD */
/* STANDARD ├OMMODORE CHARACTER SET. */
/* */
/* 15 $├──8 ╥┼┴─80 ╥EADS A MENORY LOCATION FROM ╓─├ MEMORY, SET */
/* ADDRESS TO BE READ IN ╓─├ REG 18 & 19, */
/* VALUE RETURNED IN ┴. */
/* */
/* 15 $├─├┴ ╫╥╔╘┼80 ╫RITE A VALUE TO ╓─├'S MEMORY, SET MENORY */
/* ADDRESS IN ╓─├ REG 18 & 19, VALUE IN ┴ */
/* */
/*****************************************************************************/
READVDC(PORTREG) /* READ A VDC. REG. */ CHAR PORTREG;
█
CHAR PORTREG,A,Y;
SYS(0X0F,0XCDDA,&A,&PORTREG,&Y);
RETURN(A);
▌
WRITEVDC(PORTREG,REGBYTE) CHAR PORTREG,REGBYTE;
█
CHAR Y;
* SYS(0X0F,0XCDCC,®BYTE,&PORTREG,&Y);
▌
POKEVDC(ADDR,BYTE) CHAR BYTE; UNSIGNED ADDR;
█
CHAR HI,LO,PORTREG,REGBYTE,Y;
HI = ADDR;
LO = ADDR >> 8;
PORTREG = 18;
REGBYTE = HI;
SYS(0X0F,0XCDCC,®BYTE,&PORTREG,&Y);
PORTREG = 19;
REGBYTE = LO;
SYS(0X0F,0XCDCC,®BYTE,&PORTREG,&Y);
) SYS(0X0F,0XCDCA,&BYTE,&PORTREG,&Y);
▌
PEEKVDC(ADDR) UNSIGNED ADDR;
█
CHAR HI,LO,REGBYTE,PORTREG,Y;
HI = ADDR;
LO = ADDR >> 8;
PORTREG = 18;
REGBYTE = HI;
SYS(0X0F,0XCDCC,®BYTE,&PORTREG,&Y);
PORTREG = 19;
REGBYTE = LO;
SYS(0X0F,0XCDCC,®BYTE,&PORTREG,&Y);
SYS(0X0F,0XCDD8,®BYTE,&PORTREG,&Y);
RETURN (REGBYTE);
▌
/*****************************************************************************/
/* ╥OUTINES TO ENABLE AND DISABLE THE HIRES MODE OF THE ╓─├ */
/* */
/*****************************************************************************/
HIRES() /* INIT HIRES MODE */
█
WRITEVDC(25,135);
WRITEVDC(26,113);
WRITEVDC(10,/);
▌
HIRESCOLOR(FOREGROUND) CHAR BACKGROUND;
█
/* THE BACKGROUND IS ALLWAYS BLACK */
WRITEVDC(26,(FOREGROUND * 16));
▌
CLRHIRES(FLAG)
INT FLAG;
█
CHAR BYTE;
INT I;
WRITEVDC(18,0);
WRITEVDC(19,0);
IF (FLAG) BYTE = 0;
ELSE BYTE = 0XFF;
FOR (I=0 ; I<=64 ; I++) █
WRITEVDC(31,BYTE);
WRITEVDC(30,0);
▌
▌
TEXTMODE(BANK,CHARADDR) UNSIGNED CHARADDR; INT BANK;
█
WRITEVDC(25,71);
CLRHIRES(-1);
WRITEVDC(10,96);
LOADCHAR(BANK,CHARADDR); /* C POWER'S CHARACTER SET IS AT $3800 6/
▌
LOADCHAR(FLAG,ADDR) INT BANK; UNSIGNED ADDR;
█
CHAR A,X,Y;
INT ENDING,I,J;
SYS(0X0F,0XCE0C,&A,&X,&Y); /* USE ╥╧═ ROUTINE ╔╬╔╘80 TO LOAD COMMODORE CHAR. SET */
IF (BANK) █
ENDING = ADDR+2048;
WRITEVDC(18,32);
WRITEVDC(19,0);
FOR (I=ADDR ; I<=ENDING ; I=I+8) █
FOR (J=0 ; J<=7 ; J++) █
WRITEVDC(31,PEEK(15,I+J));
▌
FOR (J=8 ; J<=15 ; J++) █
WRITEVDC(31,0);
▌
▌
▌
▌
/******************************************************************************/
/* ╨LOTING AND DRAWING ROUTINES FOR THE ╓─├ */
/* */
/* ╘HESE WOULD BE MUCH FASTER IF WRITTEN IN ═.╠., BUT ARE ╧.╦. FOR DOING */
/* DRAWINGS, BUT WOULDN'T DO FOR GAMES. */
/* */
/******************************************************************************/
PLOT(SX,SY,MODE) INT SX,SY,MODE;
█
INT VDCADDR,A,X,Y,MFLAG;
EXTERN INT CURRENTX,CURRENTY;
CHAR MASKBYTE,VDCBYTE,ADDRLO,ADDRHI,PORTREG,REGBYTE;
STATIC INT MASK[8] = █ 128,64,32,16,8,4,2,1 ▌;
VDCADDR = SY*80+SX/8;
MASKBYTE = MASK[(SX % 8)];
ADDRHI = VDCADDR >> 8;
ADDRLO = VDCADDR;
PORTREG = 18;
REGBYTE = ADDRHI;
SYS(0XF,0XCDCC,®BYTE,&PORTREG,&Y);
PORTREG = 19;
REGBYTE = ADDRLO;
SYS(0XF,0XCDCC,®BYTE,&PORTREG,&Y);
SYS(0XF,0XCDD8,&VDCBYTE,&X,&Y);
PORTREG = 18;
REGBYTE = ADDRHI;
SYS(0XF,0XCDCC,®BYTE,&PORTREG,&Y);
PORTREG = 19;
REGBYTE = ADDRLO;
SYS(0XF,0XCDCC,®BYTE,&PORTREG,&Y);
IF (MODE = 1)█
REGBYTE = (VDCBYTE MASKBYTE);
GOTO PLOTTER;
▌
IF (MODE = 2) █
REGBYTE = (VDCBYTE & (MASKBYTE));
GOTO PLOTTER;
▌
IF (MODE = 0 )█
MASKBYTE = MASKBYTE;
REGBYTE = (VDCBYTE & MASKBYTE);
GOTO PLOTTER;
▌
IF (MODE>2 MODE<0)
RETURN(0);
PLOTTER:
SYS(0XF,0XCDCA,®BYTE,&PORTREG,&Y);
RETURN(1);
▌
DRAW(X1,Y1,X2,Y2,MODE) INT X1,X2,Y1,Y2,MODE;
█
EXTERN CURRENTX,CURRENTY;
INT DX,DY,ADX,ADY,XA,YA,D,INC1,INC2;
PLOT(X1,Y1);
DX = X2-X1;
DY = Y2-Y1;
IF(DX<0) █
XA = -1;
ADX = -DX;
▌ ELSE █
XA = 1;
ADX = DX;
▌
IF(DY<0) █
YA = -1;
ADY = -DY;
▌ ELSE █
YA = 1;
ADY = DY;
▌
IF(ADY>ADY) █
INC1 = ADY << 1;
D = INC1 - ADX;
INC2 = INC1 - (ADX << 1);
WHILE(X1 != X2) █
X1 += XA;
IF(D<0)
D += INC1;
ELSE █
Y1 += YA;
D += INC2;
▌
PLOT(X1,Y1);
▌
▌ ELSE █
INC1 = ADX << 1;
D = INC1 - ADY;
INC2 = INC1 - (ADY << 1);
WHILE(Y1 != Y2) █
Y1 += YA;
IF(D<0)
D += INC1;
ELSE █
X1 += XA;
D += INC2;
▌
PLOT(X1,Y1);
▌
▌
CURRENTX = X2;
CURRENTY = Y2;
▌
DRAWTO(X,Y,MODE) INT X,Y,MODE;
█
EXTERN INT CURRENTX,CURRENTY;
DRAW(CURRENTX,CURRENTY,X,Y,MODE);
CURRENTX = X;
CURRENTY =Y;
▌
DRAWREL(DX,DY,MODE) INT DX,DY,MODE;
█
EXTERN CURRENTX,CURRENTY;
DRAW(CURRENTX,CURRENTY,CURRENTX+DX,CURRENTY+DY,MODE);
CURRENTX += DX;
CURRENTY += DY;
▌
HLINE(LENGTH,MODE) INT LENGTH,MODE;
/* DRAWS A HORZ. LINE FRON THE CURRENT ╪ ┘ COORDS */
█
EXTERN INT CURRENTX,CURRENTY;
INT I,END;
END =CURRENTX+LENGTH;
IF (LENGTH >0 )
FOR (I=CURRENTX ; I<= END ; I++) PLOT(I,CURRENTY,MODE);
ELSE
FOR (I=END ; I<= CURRENTX ; I++) PLOT(I,CURRENTY,MODE);
CURRENTX = END;
▌
VLINE(LENGTH,MODE) INT LENGTH,MODE;
/* DRAWS A VERTICAL LINE FROM THE CURRENT ╪ ┘ COORDS */
█
EXTERN INT CURRENTX,CURRENTY;
INT I,END;
END = CURRENTY+LENGTH;
IF(LENGTH>0)
=OR(I=CURRENTY ; I<=END ; I++) PLOT(CURRENTX,I,MODE);
ELSE
FOR(I=END ; I<=CURRENTY ; I++) PLOT(CURRENTX,I,MODE);
CURRENTY = END;
▌
BOX(X,Y,X1,Y1,MODE) INT X,Y,X1,Y1,MODE;
/* DRAWS A BOX OF H & W FROM CURRENT ╪ ┘ COORDINATES */
█
DRAW(X,Y,X1,Y,MODE);
DRAW(X1,Y,X1,Y1,MODE);
DRAW(X1,Y1,X,Y1,MODE);
R DRAW(X,Y1,X,Y,MODE);
▌
SCALE(Y) INT Y;
/* MAP Y COORDINATE IN TO 640 ╪ 450 SCREEN */
█
IF (Y<=449)█
Y = 449-Y;
RETURN(Y*20/45);
▌
ELSE
RETURN(-1);
▌
/**********************************************1******************************/
/* ├URSOR LOCATION ROUTINES FOR HIRES MODE */
/* */
/* ├URRENT LOCATION IS IN THE GLOBAL VARIABLES CURRENTX & CURRENTY, DRAWTO, */
/* DRAWREL,HLINE,VLINE AND BOX ALL USE THESE VARIABLES. ─RAW SETS CURRENT */
/* ╪ & ┘ TO IT'S LAST COORDINATES. ╨LOT DOSEN'T CHANGE CURRENTX OR CURRENTY */
/* OR REFERENCE THEM. */
/* */
/*****************************************************************************/
WHEREX()
█
EXTERN INT CURRENTX;
RETURN(CURRENTX);
▌
WHEREY()
█
EXTERN INT CURRENTY;
RETURN(CURRENTY);
▌
GOTOXY(X,Y) INT X,Y;
█
EXTERN INT CURRENTX,CURRENTY;
CURRENTX = X;
CURRENTY = Y;
▌